//
// Created by EmFi on 2023/5/18.
//

#ifndef DBMS_INDEXEDDATABASE_H
#define DBMS_INDEXEDDATABASE_H


#include "../BPlusTree/SerializableBPlusTree.h"
#include "Database.h"

class IndexedDatabase : public Database {
private:
    SerializableBPlusTree<double, int> xIndex;
    SerializableBPlusTree<double, int> yIndex;
    SerializableBPlusTree<double, int> zIndex;
    SerializableBPlusTree<double, int> wIndex;
    void save();
protected:
    void _clear() override;
    int _insert(Point point) override;
    int _insert(list<Point> list) override;
    Point _remove(int index) override;
    Point _update(int index, Point point) override;
public:
    explicit IndexedDatabase(const string &fn);
    ~IndexedDatabase() override;

    void printIndex();
    void optimize() override;

    int insert(Point point) override;
    int insert(list<Point> list) override;
    Point remove(int index) override;
    void clear() override;
    Point update(int index, Point point) override;

    list<Point> query(double xMin, double xMax, double yMin, double yMax, double zMin, double zMax, double wMin,
                      double wMax) override;
    list<Point> legacyQuery(double xMin, double xMax, double yMin, double yMax, double zMin, double zMax, double wMin,
                      double wMax);
};


#endif //DBMS_INDEXEDDATABASE_H
